<template>
	<view>
		<u-toast ref="uToast"></u-toast>
		<view class="control_list">
			<view class="top_img mar_bot">
				<image src="https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/azbg.png" style="width: 100%;height: 100%;"></image>
			</view>
			<view class="control_item box box-align-center box-pack-between" v-for="(item,i) in topAppControl" :key="i">
				<view class="left box box-align-center">
					<view class="">
						<image :src="item.img" style="width: 60rpx;height: 60rpx;margin-right: 10rpx;"></image>
					</view>
					<view class="tit">
						{{item.tit}}
						<view class="sub_tit">
							{{item.sub_tit}}
						</view>
					</view>
				</view>
				<view class="right">
					<u-switch v-model="item.checked" active-color="#5993ff" inactive-color="#e3e3e3" @change="((val)=>{dataChange(val, item.db_name)})"></u-switch>
				</view>
			</view>
		</view>
		
		<view class="jgy_control">
			<view class="pad_big pad_top_big pad_bot">
				<view class="header pad_bot">
					<view class="tit">
						教管壹创新研究院
					</view>
					<view class="sub_tit">
						注释：以下创新功能可以提供使用，但暂未经大批量测试，可能存在功能上的小缺陷，请选择使用。
					</view>
				</view>
				<view class="control_item box box-align-center box-pack-between" v-for="(item,i) in jgyAppControl" :key="i" @click="gotoUrl(item.url)">
					<view class="left box box-align-center">
						<image :src="item.img" mode="widthFix" style="width: 60rpx;margin-right: 10rpx;"></image>
						<view class="tit">
							{{item.tit}}
							<view class="sub_tit">
								修改时间：{{item.time}}
							</view>
						</view>
					</view>
					<view class="right">
						已开启<u-icon name="arrow-right"></u-icon>
					</view>
					<view class="line"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { editSetting, getSetting } from '../../api/systemControl';
	export default {
		data() {
			return {
				id: 0,  //other_setting表id
				topAppControl:[
					{tit:'恢复出厂设置',sub_tit:'如果关闭则学生平板端无法使用重置功能',checked:false,img:'https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/hfcc.png', db_name: 'qch_restore'},
					{tit:'WIFI共享热点',sub_tit:'如果关闭则学生平板端无法使用WIFI分享功能',checked:false,img:'https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/gxwifi.png', db_name: 'setting_hotspot'},
					{tit:'时间设置管控',sub_tit:'如果关闭则学生平板端不允许手动修改系统时间',checked:false,img:'https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/sjgk.png', db_name: 'setting_autotime'},
					{tit:'时钟功能管控',sub_tit:'如果关闭则学生平板端无法使用系统时钟功能',checked:false,img:'https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/szgk.png', db_name: 'setting_clock'},
				],
				jgyAppControl:[
					{tit:'WIFI(路由器)白名单管控部署',time:'2022-12-10 12:12:55',url:'./whiteWifi/index',img:'https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/lyq.png'},
					// {tit:'系统导航条部署',time:'2022-12-10 12:12:55',url:'',img:'https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/dht.png'},
					// {tit:'系统状态栏管控部署',time:'2022-12-10 12:12:55',url:'',img:'https://jiaoguanyi008.oss-cn-shenzhen.aliyuncs.com/miniPro/images/imgs/ztl.png'},
				]
			};
		},
		onLoad() {
			this.getSettingControl()
		},
		methods: {
			gotoUrl(url){
				if(!url) return 
				uni.navigateTo({
					url:url
				})
			},
			getSettingControl() {
				getSetting({
					id: uni.getStorageSync("snId")
				}).then(res => {
					let data = res.data
					this.id = res.data.id
					this.topAppControl.forEach((item, index, arr) => {
						arr[index].checked = Boolean(data[item.db_name])
					})
				}).catch(err => {
					
				})
			},
			//修改系统管控信息
			dataChange(val, name) {
			    let editForm = {
					userId: uni.getStorageSync('userId'),
					lastIp: uni.getStorageSync('Ip'),
					name: name,
					value: Number(val),
					snId: uni.getStorageSync('snId'),
					id: this.id
				}
				editSetting(editForm).then(res => {
					this.getSettingControl()
					this.$refs.uToast.show({
						title: res.msg,
						icon: false,
						type: 'success'
					})
				}).catch(err => {
					this.$refs.uToast.show({
						title: err.msg,
						icon: false,
						type: 'error'
					})
					this.getSettingControl()
				})
			},
		}
	}
</script>

<style lang="scss">
	.control_list{
		background-color: #fff;
		border-radius: 30rpx;
		margin: 20rpx;
		padding: 40rpx;
		.top_img{
			height: 110rpx;
			border-radius: 30rpx;
		}
		.control_item{
			padding: 20rpx 0;
		}
		.left{
			.tit{
				padding-right: 40rpx;
				font-size: 28rpx;
				.sub_tit{
					font-size: 24rpx;
					color: #cecece;
				}
			}
		}
	}
	.jgy_control{
		margin: 20rpx;
		border-radius: 30rpx;
		background-color: #e7e8ed;
		
		.header{
			.tit{
				font-size: 32rpx;
			}
			.sub_tit{
				font-size: 24rpx;
				color: #d3d4d8;
			}
		}
		.control_item{
			padding: 20rpx 0;
			position: relative;
			// margin: 40rpx 0;
			.line{
				position: absolute;
				bottom: 0;
				right: 0;
				width: 90%;
				height: 1px;
				background-color: #e1e2e7;
			}
		}
		.left{
			.tit{
				font-size: 28rpx;
				.sub_tit{
					font-size: 24rpx;
					color: #cecece;
				}
			}
		}
		.right{
			color: #cecece;
		}
	}
	
</style>
